import request from "@/api/request.js";
import {useUserStore} from '@/store/user.js'

export function getMeBasicInfo(){
    const user = useUserStore()
    return request.request({
        url:'/api/me/info',
        method: 'GET',
        headers:{
            'Token':user.cookie
        }
    })
}

export function getMeVideoCoin(){
    const user = useUserStore()
    return request.request({
        url:'/api/me/video_coin',
        method: 'GET',
        headers:{
            'Token':user.cookie
        }
    })
}

export function getMeVideoLike(){
    const user = useUserStore()
    return request.request({
        url:'/api/me/video_like',
        method: 'GET',
        headers:{
            'Token':user.cookie
        }
    })
}

//获取UP主基本信息
export function getUpBasicInfo(mid){
    const user = useUserStore()
    return request.request({
        url:'/api/up/basic_info',
        method: 'GET',
        params: { mid }, // 自动转换为 ?mid=xxx
        headers:{
            'Token':user.cookie
        },
        timeout:5000
    })
}


//获取UP主近期发布视频
export function getPublicInfo(mid){
    const user = useUserStore()
    return request.request({
        url:'/api/up/pub_video',
        method: 'GET',
        params: { mid }, // 自动转换为 ?mid=xxx
        headers:{
            'Token':user.cookie
        }
    })
}
//获取UP特征词云
export function getWordCloudInfo(mid){
    const user = useUserStore()
    return request.request({
        url:'/api/up/word_cloud',
        method: 'GET',
        params: { mid }, // 自动转换为 ?mid=xxx
        headers:{
            'Token':user.cookie
        },
        timeout: 3000
    })
}
//获取UP粉丝变化趋势
export function getTrendsInfo(mid,ps=50,pn=0,mode='hour'){
    const user = useUserStore()
    return request.request({
        url:'/api/up/change/follower',
        method: 'GET',
        params: { mid,ps,pn,mode },
        headers:{
            'Token':user.cookie
        }
    })
}
//获取用户关注列表
export function getLike(uid){
    const user = useUserStore()
    return request.request({
        url:'/api/user/like',
        method: 'GET',
        params: { uid }, // 自动转换为 ?mid=xxx
        headers:{
            'Token':user.cookie
        }
    })
}

//关注UP主
export function doLikeUp(data) {
    const user = useUserStore()
    return request.request({
        url: '/api/user/like',
        method: 'POST',
        data: data,  // data内容：mid,uid
        headers: {
            'Token': user.cookie,
            'Content-Type': 'application/json'  // 明确指定内容类型
        }
    })
}
//取消关注UP主
export function cancelLikeUp(data) {
    const user = useUserStore()
    return request.request({
        url: '/api/user/like',
        method: 'DELETE',
        data: data,  // data内容：mid,uid
        headers: {
            'Token': user.cookie,
            'Content-Type': 'application/json'  // 明确指定内容类型
        }
    })
}

export function checkCookie(){
    const user = useUserStore()
    return request.request({
        url:'/api/check',
        method: 'GET',
        headers:{
            'Token':user.cookie
        }
    })
}